define(function (require, exports) {
	var $ = require('jquery');
	var pubjs = require('pubjs');
	var util = require('util');
	var view = require('@base/view');
	// var dspUtil = require('dspUtil');

	var Base = view.container.extend({
		init: function(config) {
			config = pubjs.conf(config, {
				'class': 'P-campaignBasic',
				'tplFile': '/tpl/campaign/editStep/product.tpl',
				'vModel': {

				},
				// tips配置
				'tipOpts': {

				}
			});

			this.Super('init', arguments);
		},
		afterBuild: function() {
			var self = this;
			var c = self.getConfig();
			var vm = self.vm.$;
			self.getDOM().addClass(c.class);


			var opts = {
				'materialGroup': {}
			};

			self.buildFromTemplate(util.extend(opts, c.tipOpts));
		},

		afterBuildTemplate: function(){

		},
		validate: function(data){
			var self = this;
			data = data || self.getData();
			if (data) {
				if(!data.MainStrategy || !data.MainStrategy.MaterialGroup || !data.MainStrategy.MaterialGroup.length) {
					pubjs.alert(LANG("素材组不能为空，请选择相应的素材组"));
					return false;
				}
			}

			return true;
		},
		onPlanChange: function (ev) {
			this.$.materialGroup.setSelectParam({PlanId: ev.param.id});
		},
		setData: function(data){
			var self = this;
			if(data && data.MainStrategy && data.MainStrategy.MaterialGroup){
				self.$.materialGroup.setData(data.MainStrategy.MaterialGroup);

				self.$MaterialGroupId = data.MainStrategy.MaterialGroupId || null;
			}
			return self;
		},
		getData: function(){
			var self = this;
			var data = {
				MainStrategy: {
					MaterialGroup: self.$.materialGroup.getData()
				}
			};
			if(self.$MaterialGroupId){
				data.MainStrategy.MaterialGroupId = self.$MaterialGroupId;
			}

			return data;
		},
		save: function(){
			if(this.validate()){
				return this.getData();
			}
		},
		reset: function(){
			this.vm.reset();
			this.$.materialGroup.reset();
			this.$MaterialGroupId = null;
			return this;
		}

	});

	exports.base = Base;

})